// page_other/shujuyye/shujuyye.js
let app = getApp()
let yuming = app.globalData.yuming;
const request = require('../../config/request');

Page({

  /**
   * 页面的初始数据
   */
  ...request,
  data: {
    yuming: yuming,
    heights: "",
    title: '总营业额明细',
    time: '', // 筛选时间
    istime: false, //弹出时间筛选
    zjyList: []
    // zjyList: [{
    //     date: '2022-06-28',
    //     mxList: [{
    //         content: '交易收入-**生',
    //         money: '+12.80',
    //         time: '16:15:43'
    //       },
    //       {
    //         content: '交易收入-*福',
    //         money: '+18.20',
    //         time: '15:11:24'
    //       }
    //     ]
    //   },
    //   {
    //     date: '2022-06-26',
    //     mxList: [{
    //         content: '交易收入-**意',
    //         money: '+24.60',
    //         time: '12:55:33'
    //       },
    //       {
    //         content: '交易收入-*贯',
    //         money: '+14.70',
    //         time: '12:35:21'
    //       },
    //       {
    //         content: '交易收入-*虎',
    //         money: '+34.60',
    //         time: '11:45:35'
    //       }
    //     ]
    //   }
    // ],
  },
  getzjyList() {
    let that = this;
    wx.showLoading({
      title: '加载中',
      icon: 'none'
    })
    this.myRequest(yuming + 'shop/shop_operating_list', {
      shopId: wx.getStorageSync('shopId'),
      month: that.data.time
    }, 'POST').then(res => {
      wx.hideLoading();
      if (res.data.code == 200) {
        let zjyList = res.data.data;
        let paytime = '';
        zjyList.forEach(item => {
          item.Paylist.forEach(items => {
            paytime = items.createtime.split(' ')
            items.paytime = paytime[1]
          })
        })
        this.setData({
          zjyList
        })
      }
    })
  },
  tan() {
    this.setData({
      istime: !this.data.istime
    })
  },
  // 月
  bindyue(e) {
    this.setData({
      time: e.detail.value
    })
  },
  que() {
    if (new Date(this.data.time).getTime() > new Date().getTime()) {
      wx.showToast({
        title: '无法查看该年数据哦~',
        icon: 'none'
      })
      return
    }
    this.setData({
      istime: !this.data.istime
    })
  },
  xq(e) {
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/page_other/shujuyyexq/shujuyyexq?id=' + id,
    })
  },
  backs() {
    wx.navigateBack({
      delta: 0
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      heights: wx.getMenuButtonBoundingClientRect().top + 5
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    let date = new Date();
    let year = date.getFullYear();
    let month = date.getMonth() + 1
    month = ('0' + month).substr(-2);
    this.setData({
      time: year + "-" + month
    })
    this.getzjyList();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },
})